
********************************************************************************
*This file analyzes fund LPI
********************************************************************************

cd ".."

use "data_intermediate/fund_ltisample_haircutrobust_new.dta", clear

merge 1:1 year quarter crsp_portno using "data_input/fund_characteristics.dta"

drop if _merge==2
drop _merge 


gen lnassets=log(assetstotal)

gen cashratio=(a_mf_treas+a_mf_ag_deb+a_mf_cash+a_mf_ag_mbscmo)/assetstotal


gen assetilliquidity=(a_mf_com_loan*awgt_com_loan + awgt_cmoabs*a_mf_cmoabs+ awgt_bond*a_mf_bond ///
+awgt_mm*a_mf_mm+awgt_muni*a_mf_muni+ awgt_eq* a_mf_eq)

replace assetilliquidity=1-assetilliquidity/(a_mf_com_loan+a_mf_cmoabs+a_mf_bond+a_mf_mm+ a_mf_muni+ a_mf_eq)


foreach x in lpi lpi_1 lpi_2 lpi_3 lpi_4 lpi_5 lpi_6 lpi_7 lpi_8 lpi_9 lpi_10  expected_lti_JLW {
replace `x'=`x'*10000
}
rename expected_lti_JLW lpi_jlw

gen nlpi=lpi-(mgmt_fee+actual_12b1)/liq_value_pct


collapse (mean) assetstotal flow_trunc  lnage retail exp_ratio lpi lpi_1 ///
lpi_2 lpi_3 lpi_4 lpi_5 lpi_6 lpi_7 lpi_8 lpi_9 lpi_10 nlpi  lpi_jlw   ///
assetilliquidity cashratio  lnassets ///
cash_weight treas_weight ag_deb_weight ag_mbscmo_weight com_loan_weight mm_weight ///
muni_weight bond_weight cmoabs_weight eq_weight, by (crsp_portno) 


replace flow_trunc=-flow_trunc

foreach x in flow_trunc  cashratio assetilliquidity  exp_ratio lnage  lnassets  {
winsor2 `x', cuts (1 99) replace
rename `x' temp 
egen `x'=std(temp)
drop temp
}

********************************************************************************
*Cross-sectional determinants of Fund LPI
********************************************************************************

label var flow_trunc "Outflow" 
label var assetilliquidity "Asset Illiquidity"
label var cashratio  "Cash Ratio"
label var lnassets   "Asset Size"
label var lnage  "Age"
label var retail  "Retail"
label var exp_ratio  "Expense Ratio"


eststo clear
eststo: reg lpi flow_trunc  cashratio  assetilliquidity exp_ratio 
eststo:reg lpi flow_trunc  cashratio assetilliquidity  exp_ratio retail lnage  lnassets 


eststo: reg lpi_8 flow_trunc  cashratio  assetilliquidity exp_ratio 
eststo:reg lpi_8 flow_trunc  cashratio assetilliquidity  exp_ratio retail lnage  lnassets 

capture: esttab using  "output/fundcross.tex", ///
replace b(2) se(2) star(* 0.10 ** 0.05 *** 0.01  )  ///
mgroups("LPI" "LPI (NAV Striking)", pattern( 1 0 1 0 ) ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
ar2   label  nomtitles nodepvars nonotes  s(N r2_a, ///
label(  "Observations" "Adjusted R2") ///
fmt(  %9.0fc 2 )) 

********************************************************************************
*Summmary Statistics Table Output
********************************************************************************



label var lpi "LPI"
label var lpi_1 "LPI (10\% NAV Striking)"
label var lpi_2 "LPI (20\% NAV Striking)"
label var lpi_3 "LPI (30\% NAV Striking)"
label var lpi_4 "LPI (40\% NAV Striking)"
label var lpi_5 "LPI (50\% NAV Striking)"
label var lpi_6 "LPI (60\% NAV Striking)"
label var lpi_7 "LPI (70\% NAV Striking)"
label var lpi_8 "LPI (80\% NAV Striking)"
label var lpi_9 "LPI (90\% NAV Striking)"

label var lpi "LPI"
label var lpi_jlw "LPI"


replace cash_weight=cash_weight*100
label var cash_weight "Cash"

replace treas_weight=treas_weight*100
label var treas_weight "Treasuries"

replace ag_deb_weight=ag_deb_weight*100
label var ag_deb_weight "Agency Debentures"

replace ag_mbscmo_weight=ag_mbscmo_weight*100
label var ag_mbscmo_weight "Agency MBS/CMO"


replace mm_weight=mm_weight*100
label var mm_weight "Money Market"

replace muni_weight=muni_weight*100
label var muni_weight "Muni"

replace bond_weight=bond_weight*100
label var bond_weight "Corporate Bonds"

replace eq_weight=eq_weight*100
label var eq_weight "Equities"


replace cmoabs_weight=cmoabs_weight*100
label var cmoabs_weight "CMO/ABS"

 

eststo clear
estpost summarize  cash_weight treas_weight ag_deb_weight ag_mbscmo_weight mm_weight muni_weight bond_weight cmoabs_weight eq_weight  flow_trunc , detail 
esttab  using "output/fundstats_baseline.tex", replace cells("mean(fmt(2)) sd(fmt(2)) p25(fmt(2))  p50(fmt(2))  p75(fmt(2)) ") nomtitle  width(0.8\hsize) label  nonumber noobs 

eststo clear
estpost summarize lpi lpi_1 lpi_2  lpi_3  lpi_4  lpi_5  lpi_6  lpi_7  lpi_8  lpi_9, detail 
esttab  using "output/fundlpistats_observed.tex", replace cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1))  p50(fmt(1))  p75(fmt(1)) ") nomtitle  width(0.8\hsize) label  nonumber noobs


eststo clear
estpost summarize lpi_jlw , detail 
esttab  using "output/fundlpistats_jlw.tex", replace cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1))  p50(fmt(1))  p75(fmt(1)) ") nomtitle  width(0.8\hsize) label  nonumber noobs


eststo clear
estpost summarize nlpi, detail 
esttab  using "output/fundlpistats_observed_netfees.tex", replace cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1))  p50(fmt(1))  p75(fmt(1)) ") nomtitle  width(0.8\hsize) label  nonumber noobs


***********************************************************************************
*Robustness Table: Loan liquidation costs are X times HY
************************************************************************************

use "data_intermediate/fund_ltisample_haircutrobust_1.dta", clear

rename lpi lpi_hy1

merge 1:1 crsp_portno  year quarter   using "data_intermediate/fund_ltisample_haircutrobust_2.dta"
drop _merge

rename lpi lpi_hy2

merge 1:1 crsp_portno  year quarter  using "data_intermediate/fund_ltisample_haircutrobust_3.dta"
drop _merge

rename lpi lpi_hy3

merge 1:1 crsp_portno  year quarter  using "data_intermediate/fund_ltisample_haircutrobust_4.dta"
drop _merge

rename lpi lpi_hy4

replace lpi_hy1=lpi_hy1*10000
replace lpi_hy2=lpi_hy2*10000
replace lpi_hy3=lpi_hy3*10000
replace lpi_hy4=lpi_hy4*10000


collapse  (mean)  lpi_hy1 lpi_hy2 lpi_hy3 lpi_hy4, by (crsp_portno) 

label var lpi_hy1 "LPI (HY1)"
label var lpi_hy2 "LPI (HY2)"
label var lpi_hy3 "LPI (HY3)"
label var lpi_hy4 "LPI (HY4)"

eststo clear
estpost summarize lpi_hy1 lpi_hy2 lpi_hy3 lpi_hy4, detail 
esttab  using "output/fundlpistats_hy2.tex", replace cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1))  p50(fmt(1))  p75(fmt(1)) ") nomtitle   width(0.8\hsize) label  nonumber noobs

***********************************************************************************
*Robustness: Alternative muni liquidation cost
************************************************************************************

use "data_intermediate/fund_ltisample_haircutrobust_Muni.dta", clear

collapse  (mean)  lpi, by (crsp_portno) 

label var lpi "LPI"

replace lpi=lpi*10000

eststo clear
estpost summarize lpi, detail 
esttab  using "output/fundlpistats_muni.tex", replace cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1))  p50(fmt(1))  p75(fmt(1)) ") nomtitle   width(0.8\hsize) label  nonumber noobs
